home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8051 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  924 b 

  1. Path: netnews1.apci.com!usenet
  2. From: wardmw@apci.com (Martin Ward)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Leap Years
  5. Date: Fri, 01 Mar 1996 07:56:02 GMT
  6. Organization: Air Products Europe
  7. Message-ID: <4h6ara$mu@netnews1.apci.com>
  8. References: <8BA8405.02C70020E1.uuout@sourcebbs.com>
  9. Reply-To: wardmw@apci.com
  10. NNTP-Posting-Host: p1862.apci.com
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. david.mohorn@sourcebbs.com (DAVID MOHORN) typed:
  14.  
  15. >How do you feature out leap years?  If its evenly divisible by 400 and
  16. >4?
  17.  
  18. The following code will do it:
  19.  
  20. /* Return TRUE if iYear is a leap year, otherwise return FALSE */
  21.  
  22. int IsLeapYear(int iYear)
  23. {
  24.     /* Check for a 4000th year */
  25.     if ( (iYear % 4000) == 0)
  26.         return FALSE;
  27.  
  28.     /* Check for 400th year */
  29.     if ( (iYear % 400) == 0)
  30.         return TRUE;
  31.  
  32.     /* Check for century */
  33.     if ( (iYear % 100) == 0 )
  34.         return FALSE;
  35.  
  36.     /* C
  37.     if ( (iYear % 4) == 0 )
  38.         return TRUE;
  39.  
  40.     return FALSE;
  41. }
  42.  
  43. HTH.
  44.  
  45. |\/|
  46.  
  47.